{% extends "base.html" %}

{% block pagedef %} Upload collection {% endblock %}

{% block script %}
<script type="text/javascript"> 

$(document).ready(function() { 
    var error_msg = "{{error_msg|safe}}";
    if (error_msg){
        $('#error').jGrowl( "<b>"+error_msg+"</b>", { life: 10000 } );
    }
});

$(document).ready(function(){
    $('#progressbar').hide();
    $("[blockui='wait_progress']").click(function() { 
        var refreshId1 = setInterval(function() {
            $.getJSON("progressbar", {}, function(data){
                if( data.initial_load >0 ){ 
                    $("#progressbar").show();
                }
                $('#progressbar').progressBar(data.initial_load);
                if( data.initial_load >= 100 ){ 
                    $('#progressbar').progressBar(0);
                    $('#progressbar').hide();
                    clearInterval(refreshId1);
                }
            });
        }, 500);
    });
    $("span#nexus").click(function() {
    	$("textarea").attr("value","#nexus\nbegin trees;\ntree aa = ((rattus, pan), homo);\ntree bb = ((homo_sapiens, mus_france), (pan, rattus));\ntree cc = (homo, (bos, pan));\ntree dd = ((mus, rattus),pan);\nend;\n");
    	$("#demo_delimiter").attr("value","_");
    });
    $("span#newick").click(function() {
    	$("textarea").attr("value","((rattus, pan), homo);\n((homo_sapiens, mus_france), (pan, rattus));\n(homo, (bos, pan));\n((mus, rattus),pan);\n");
    	$("#demo_delimiter").attr("value","_");
    }); 
        $("input#badreset").click(function() {
    	$("textarea").attr("value","");
    	$("#demo_delimiter").attr("value","_");
    });
    
    
     
});


</script>
{% endblock %}

{% block idpage %}/phyloexplorer/{% endblock %}

{% block content %}
<div id="error"></div>
<div id="progressbar"></div>
{% if msg %}
    <div id="error" class="error"><center>{{ msg }}</center></div>
{% endif %}
    <fieldset>
        <legend>Choose the file containing your tree collection in newick or nexus...</legend>
        <form action="/phyloexplorer/statistics" method="post" enctype="multipart/form-data">
           <br/>
	    <b>Filename:</b> <input type="file" name="myFile" class="button" /><br />
            <b>Space delimiter:</b> <input type="text" size="1px" name="delimiter" value="_" /> used for complex taxon names (e.g., "_" for "mus_musculus_IRBP" or "$" for "mus$musculus$IRBP", ... )<br /><br/>
	    <input type="reset" class="button" value="Reset" />
            <input type="submit" class="button" blockui="wait_progress" value="Upload & explore" />
            <input type="hidden" name="new_collection" value="true" />
        </form>
    </fieldset>
    <br />
    <fieldset>
        <legend>... OR paste your tree collection in newick or nexus...</legend>
        <form action="/phyloexplorer/statistics" method="post" enctype="multipart/form-data">
            <textarea rows="10" cols="80" name="myFile" value=""></textarea><br />
            <b>Space delimiter:</b> <input id="demo_delimiter" type="text" size="1px" name="delimiter" value="_" /> used for complex taxon names (e.g., "_" for "mus_musculus_IRBP" or "$" for "mus$musculus$IRBP", ... )<br />
	    
	    <span class="example_button" id="nexus">nexus example </span> &nbsp
	    <span class="example_button" id="newick"> newick example </span><br/><br/>
	    <input type="button" class="button" value="Reset" id="badreset"/>
            <input type="submit" class="button" blockui="wait_progress" value="Upload & explore" />
            <input type="hidden" name="new_collection" value="true" />
        </form>
    </fieldset>
    <br />
    <fieldset>
        <legend>... OR enter a query for TreeBase</legend>
        <form action="/phyloexplorer/statistics" method="post" enctype="multipart/form-data">
            <input type="text" size="80px" name="query_treebase" /><br/>
            <tt id="exemplequery"> e.g: <b>{muridae} > 25 and ({mus}==1 or {rattus}==1)  </b><br/><br/>
            <input type="reset" class="button" value="Reset" />
            <input type="submit" class="button" blockui="wait_progress" value="Retrieve & explore" />
            <br />
        </form>
    </fieldset>
{% endblock %}
